#ifndef TVCANVAS_H
#define TVCANVAS_H

#include <QObject>
#include <QMediaPlayer>
#include "qtquick2applicationviewer.h"
#include <QVariantMap>
#include "server.h"
#include <QFileSystemWatcher>
#include <QStringList>
#include "cachedimageprovider.h"
#include <QTime>

class TvCanvas : public QObject
{
    Q_OBJECT
public:
    explicit TvCanvas(QObject *parent = 0);
    
signals:
    
public slots:

private slots:
    void imgFolderChange(const QString &path);
    void videoFolderChange(const QString &path);
    void setTimeSchedule(const int &service, const QString &schedule);
    void timerTimeout();

signals:
    void addSlide(const QString &path);
    void removeSlide(const QString &path);
    void addVideo(const QString &path);
    void removeVideo(const QString &apth);


private:
    bool loadConfig();
    void saveConfig();
    void setupWindow();
    void setupServer();
    void setupSlideshow();
    void setupVideoPlayer();
    void setupRunningLine();
    void setupMessage();
    void setupWatchers();
    void setupSchedule();
    enum SEARCH_RESULT{OFF, ON, NOT_FOUND};
    SEARCH_RESULT findTime(int service, const QTime &curTime);
    QtQuick2ApplicationViewer * m_qmlViewer;
    QObject * m_qmlRoot;
    QVariantMap m_config;
    Server * m_qrsServer;
    qrs::TvService * m_service;
    QFileSystemWatcher * m_imgWatcher;
    QFileSystemWatcher * m_videoWatcher;
    QStringList m_slides;
    QStringList m_videos;
    CachedImageProvider *m_cached;
    QList<QList<QTime> > m_onTime;
    QList<QList<QTime> > m_offTime;
};

#endif // TVCANVAS_H
